const express = require('express');
const ejs = require('ejs');
const path = require('path');
const app = express();
// 引入路由 
const UserRouter = require('./router/user')
const ApiRouter = require('./router/api')

// ejs
app.set('views', path.join(__dirname, '/views'))
app.set('view engine', 'html');
app.engine('html', ejs.renderFile)
// post参数
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
// 静态资源配置
app.use(express.static(path.join(__dirname, '/public')))


app.use('/', UserRouter)
app.use('/api', ApiRouter)

// 错误处理中间件 404 页面
app.use((req, res, next) => {
  res.render('404', {
    msg: '404 -> NO FOUND'
  })
})

app.listen(5555, () => {
  console.log('server port is : 5555')
})
